#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=1e6+5;
int Q,l,r,a[N];
signed main(){
	freopen("comb.in","r",stdin);
	freopen("comb.out","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0),cout.tie(0);
	for(int i=1;i<=1000000;i++) {
		int x=i;
		while(x%2==0) {
			x>>=1;
			++a[i];
		}
	}
	for(int i=1;i<=1000000;i++) a[i]+=a[i-1];
	cin>>Q;
	while(Q--) {
		cin>>l>>r;
		int ans=0;
		for(int n=l;n<=r;n++)
		for(int m=n;m<=r;m++) {
			if(a[m]-a[m-n]==a[n])
				++ans;
		}
		cout<<ans<<"\n";
	}
	return 0;
}
/*
*/
